﻿using MediatR;
using Mysqlx.Crud;
using RedDragon.Common.Domain.warehouse;
using RedDragon.Common.Infrastructure.Interface;
using RedDragon.RBAC.ErrorCodeEnum;
using System.Security.Cryptography;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Application.Common.AddNLog
{
    public class AddNLogHandler : IRequestHandler<AddNLogCommon, Result>
    {
		public readonly IBaseRepository<LogEntry> LogEntryRepository;

        public AddNLogHandler(IBaseRepository<LogEntry> logEntryRepository)
        {
            LogEntryRepository = logEntryRepository;
        }

        public async Task<Result> Handle(AddNLogCommon request, CancellationToken cancellationToken)
        {
			try
			{
				var result = new Result() { Code = (int)CommonErrorCode.Added };
				var HandleTime = DateTime.UtcNow;
				var AddLogData = $"操作人:{request.HandleName};操作行为:{request.HandleContext};操作时间:{HandleTime}";
				var sql = "insert LogEntry values (@Id,@LogData,@HandleName,@HandleContext,@HandleTime,@Pid,@IsDelete)";
				var Addnum = new LogEntry
				{
					Id = request .Id,
                    LogData = AddLogData,
                    HandleName = request.HandleName,
                    HandleContext = request.HandleContext,
                    Pid = request.Pid,
                    IsDelete = request.IsDelete,
                };
                LogEntryRepository.Add(Addnum);
                return result;
            }
			catch (Exception)
			{

				throw;
			}
        }
    }
}
